define("index",["jquery"],function () {
	
	return {
		scroll:function () {
			//共用方法 信息滚动
			function scroll(ele1,ele2,ele3) {
				//console.log(part2.scrollTop);
				if(ele1.offsetHeight-ele3.scrollTop<=0){
					ele3.scrollTop-=ele2.offsetHeight
				}else{
					ele3.scrollTop++
				}
			}
			var part2=document.querySelector(".part2")
			var part3=document.querySelector(".part3")
			var scroll1=document.querySelector(".scroll1")
			var scroll2=document.querySelector(".scroll2")
			//免费查询
			part2.timer=setInterval(function () {
				scroll(scroll1,scroll2,part2)
			},50)
			part2.onmouseenter=function () {
				clearInterval(part2.timer)
			}
			part2.onmouseleave=function () {
				part2.timer=setInterval(function () {
					scroll(scroll1,scroll2,part2)
				},50)
			}
			//选择闪猫
			part3.timer=setInterval(function () {
				scroll(scroll1,scroll2,part3)
			},50)
			part3.onmouseenter=function () {
				clearInterval(part3.timer)
			}
			part3.onmouseleave=function () {
				part3.timer=setInterval(function () {
					scroll(scroll1,scroll2,part3)
				},50)
			}
		},
		rotation() {
			//banner轮播图
			var Img=0
			//console.log($(".banner").children("div"));
		function autoplay() {
			Img++
			if(Img>2){
				Img=0
			}
		
			$(".banner").children("div").eq(Img).animate({opacity:1}).siblings("div").animate({opacity:0})
			$(".banner li").eq(Img).animate({opacity:0.9}).siblings().animate({opacity:0.3})
		}
		//定时轮播
		var timer=setInterval(autoplay,2000)
			//鼠标滑入滑出
			$(".banner").hover(function () {
				clearInterval(timer)
				$(".banner span").show(150)
			},function () {
				timer=setInterval(autoplay,2000)
				$(".banner span").hide(150)
			})
			//点击 点点
			$(".banner li").each(function (index,ele) {
				$(ele).click(function () {
					Img=$(this).index()-1
					autoplay()
				})
			})
			//左右箭头点击
			$(".banner span").eq(0).click(function () {
				clearInterval(timer)
				Img--
				if(Img<0){
					Img=2
				}
				$(".banner").children("div").eq(Img).stop(false,true).animate({opacity:1}).siblings("div").animate({opacity:0})
				$(".banner li").eq(Img).stop(false,true).animate({opacity:0.9}).siblings().animate({opacity:0.3})
			
			})
			
			
			$(".banner span").eq(1).click(function () {
				clearInterval(timer)
				autoplay()
			})
		},
		log_reg(){
			//点击 显示登录注册页面
			$(".lg").click(function () {
				$(".login").css("display","block")
			})
			$(".close").click(function () {
				$(".login").css("display","none")
			})
		},
		allServer_show(){
			$(".lAll ul").children("li").each((index,ele)=>{
				$(ele).hover(function () {
					var $index=$(this).index()
					
					$(".detail").eq($index).css("display","block").siblings(".detail").css("display","none")
				},function () {
					$(".detail").css("display","none")
				})
			})
		},
		move(){
			$(".login_center li").each(function (index,ele) {
				$(ele).click(function () {
					$index=$(this).index()
					$(this).addClass("current").siblings().removeClass("current")
					$(".content form").eq($index).css("display","block").siblings().css("display","none")
				})
			})
		},
		return_top(){
			$(window).scroll(function () {
				if($(this).scrollTop()>1000){
					$(".return_top").css("display","block")
				}else{
					$(".return_top").css("display","none")
				}
				
			})
			var timer=0
			$(".return_top").click(function () {
				clearInterval(timer)
				timer=setInterval(function () {
					var target=0
					var current=$(window).scrollTop()
					console.log(current);
					var step=(target-current)/10
					step=step>0?Math.ceil(step):Math.floor(step)
					window.scrollTo(0,current+step)
					if(current==target){
						clearInterval(timer)
					}
				},20)
			})
		},
		customer_move(){
			var imgIndex=0
			var timer=0
			function autoplay() {
				//clearInterval(timer)
				imgIndex++
				if(imgIndex>1){
					imgIndex=0
					$(".playImg ul").offsetLeft=0
				}
				
				$(".playImg ul").animate({
					left:1180*-imgIndex
				})
			}
			 timer=setInterval(autoplay,2000)
			$(".cus_left").click(function () {
				//clearInterval(timer)
				$(".playImg ul").stop()
				autoplay()
			})
			$(".cus_right").click(function () {
				$(".playImg ul").stop()
				//clearInterval(timer)
			
				autoplay()
				
			})
		},
		logins(){
			let ouse=JSON.parse(sessionStorage.getItem("userInfo"))
			console.log(ouse);
			if(ouse!=null){
				$("#login").html(ouse.u_tel+",欢迎您")
				$("#login").parents("ul").prepend("<li><a id='quite''>退出</a></li>")
				$("ul").on("click","#quite",function () {
					sessionStorage.removeItem("userInfo")
					window.location="login.html"
				})
			}
			
			$.ajax({
				url:"../../server/getlist.php",
			}).then(function (res) {
				res.forEach((ele,index)=>{
					var html=`
								
									<li><a href="detail.html?id=${ele.cid}">
										<h5>${ele.ctitle}</h5>
										<p class="p_one">${ele.ccontent}</p>
										<p class="sj_price"> ${ele.cprice}元</p>
										<p class="sc_price">市场价：${ele.cprice1}元起</p>
										<input type="button" value="立即购买" data-info='${JSON.stringify(ele)}'/>
										</a></li>`
					$(".set_center ul").append(html)
				})
			})
		}
	}
})